﻿@page "/Fin/PaymentDetail/Edit"
@using nERP.ViewModel.Fin.PaymentDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.PayId" Items="AllPays" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g5b3663f162e047969b6503696b76cd1d" />
            <BootstrapInput @bind-Value="@Model.Entity.PayDetailCode" />
            <Select @bind-Value="@Model.Entity.BuyId" Items="AllBuys" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gb4c2047b198149d3aeca03260c013e85" />
            <BootstrapInput @bind-Value="@Model.Entity.Amount1" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Amount2" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Amount3" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Amount4" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private PaymentDetailVM Model = new PaymentDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Fin/PaymentDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllPays = new List<SelectedItem>();
    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllPays = await WtmBlazor.Api.CallItemsApi("/api/Fin/PaymentDetail/GetPayments");
        AllPays.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Fin/PaymentDetail/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<PaymentDetailVM>($"/api/Fin/PaymentDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
